package com.zzl.car.service;

import com.zzl.car.entity.LoveCarScore;
import com.zzl.car.exception.ZdpException;
import com.zzl.car.mapper.ZzwInsuranceMapper;
import com.zzl.car.mapper.ZzwLoveCarScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ZzwLoveCarScoreService {
    @Autowired
    private ZzwLoveCarScoreMapper loveCarScoreMapper;

    public String three(Map<String,LoveCarScore> map){

        int result = 0;

        loveCarScoreMapper.deleteLoveCarScore();
        LoveCarScore l1 = map.get("form1");
        result += loveCarScoreMapper.modifyLoveCarScore(l1);
        LoveCarScore l2 = map.get("form2");
        result += loveCarScoreMapper.modifyLoveCarScore(l2);
        LoveCarScore l3 = map.get("form3");
        result += loveCarScoreMapper.modifyLoveCarScore(l3);

        if(result == 3)
        return "1";
        else{
            loveCarScoreMapper.deleteLoveCarScore();
            throw new ZdpException(2999,"修改失败");
        }
    }

    public String four(Map<String,LoveCarScore> map){

        int result = 0;

        loveCarScoreMapper.deleteLoveCarScore();
        LoveCarScore l1 = map.get("form1");
        result += loveCarScoreMapper.modifyLoveCarScore(l1);
        LoveCarScore l2 = map.get("form2");
        result += loveCarScoreMapper.modifyLoveCarScore(l2);
        LoveCarScore l3 = map.get("form3");
        result += loveCarScoreMapper.modifyLoveCarScore(l3);
        LoveCarScore l4 = map.get("form4");
        result += loveCarScoreMapper.modifyLoveCarScore(l4);

        if(result == 4)
            return "1";
        else{
            loveCarScoreMapper.deleteLoveCarScore();
            throw new ZdpException(2999,"修改失败");
        }
    }

    public String five(Map<String,LoveCarScore> map){

        int result = 0;

        loveCarScoreMapper.deleteLoveCarScore();
        LoveCarScore l1 = map.get("form1");
        result += loveCarScoreMapper.modifyLoveCarScore(l1);
        LoveCarScore l2 = map.get("form2");
        result += loveCarScoreMapper.modifyLoveCarScore(l2);
        LoveCarScore l3 = map.get("form3");
        result += loveCarScoreMapper.modifyLoveCarScore(l3);
        LoveCarScore l4 = map.get("form4");
        result += loveCarScoreMapper.modifyLoveCarScore(l4);
        LoveCarScore l5 = map.get("form5");
        result += loveCarScoreMapper.modifyLoveCarScore(l5);

        if(result == 5)
            return "1";
        else{
            loveCarScoreMapper.deleteLoveCarScore();
            throw new ZdpException(2999,"修改失败");
        }
    }


    /**
     * 获取所有爱车指数分信息
     * @return
     */
    public List<LoveCarScore> getLoveCarScore (){
       return loveCarScoreMapper.getLoveCarScore();
    }
}
